/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package buttonexample;

import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

/**
 *
 * @author anxiaochen
 */
public class user 

{   
   private JFrame f = new JFrame("WELCOME,REGIST OR LOGIN,PLEASE!");
        
	private JTextField username = new JTextField(10);
	private JPasswordField password = new JPasswordField(10); 
	private JLabel user = new JLabel("User");
	private JLabel pwd = new JLabel("Password");
	private JButton logon = new JButton("Logon on");
        private JButton regist = new JButton("regist");
	
        

public user(){

    
    JPanel p = new JPanel();
		p.setLayout(new GridLayout(2, 2));
		
		p.add(user);
		p.add(username);
		p.add(pwd);
		p.add(password);
	
		f.add(p, BorderLayout.NORTH);
		f.add(logon, BorderLayout.SOUTH);
		f.add(regist, BorderLayout.CENTER);
                
                

                logon.addMouseListener(new MouseListener(){

			public void mouseClicked(MouseEvent e) {
				
					if(username.getText().trim().equals("") || password.getText().trim().equals("")){
						JOptionPane.showMessageDialog(null, "Password/Username is blank. Please input!");
						return;
					}
                                        
					
					if(username.getText().equals("chen") && password.getText().equals("123")){
						JOptionPane.showMessageDialog(null, "Logon on success");
                                                f.setVisible(false);
					}else{
						username.setText("");
						password.setText("");
						JOptionPane.showMessageDialog(null, "Username/password incorrect. Please try again");
						
					}
				}
				
			

			public void mouseEntered(MouseEvent e) {}
			public void mouseExited(MouseEvent e) {}
			public void mousePressed(MouseEvent e) {}
			public void mouseReleased(MouseEvent e) {}
		});
                regist.addMouseListener(new MouseListener(){

			public void mouseClicked(MouseEvent e) {
				if(!username.getText().equals("")&&!username.getText().equals(null) && !password.getText().equals("")&&!username.getText().equals(null)){
						JOptionPane.showMessageDialog(null, "regist success");
                                                f.setVisible(false);
				}else{
						username.setText("");
						password.setText("");
						JOptionPane.showMessageDialog(null, "can't be empty, Please try again");
						
					}
			}
				
			

			public void mouseEntered(MouseEvent e) {}
			public void mouseExited(MouseEvent e) {}
			public void mousePressed(MouseEvent e) {}
			public void mouseReleased(MouseEvent e) {}
		});
                
		f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		f.setVisible(true);
		f.setBounds(800, 200, 400, 400);
		f.pack();
		

}
     
    
}
